<?php
/**
 * Category
 *  
 * @author liumingl
 * @version 
 */
class News_Resource_Category extends GM_Model_Resource_Db_Table_Abstract implements News_Resource_Category_Interface
{
    /**
     * The default table name 
     */
    protected $_name = 'news_category';
    protected $_primary = 'cid';
	protected $_rowClass = 'News_Resource_Category_Item';
	
	protected $_referenceMap = array(
        'SubCategory' => array(
            'columns' => 'cup',
            'refTableClass' => 'News_Resource_Category',
            'refColumns' => 'cid',
        )
    );
	
	/**
     * @param unknown_type $parentId
     */
    public function getCategoriesByParentId($parentId)
    {
        $select = $this->select()
                        ->where('cup = ?', $parentId)
                        ->order('displayorder');
                        
        return $this->fetchAll($select);
    }
    
	/**
     * @param unknown_type $id
     */
    public function getCategoryById ($id)
    {
        $select = $this->select()
                       ->where('cid = ?', $id);
                       
        return $this->fetchRow($select);
    }
   
}

